/**
 * @Author @fiber-cloud
 * @Date 2025/8/31 21:54
 */
public class ThreadDemo8 {
    public static void main(String[] args) throws InterruptedException {

        Object object = new Object();
        Thread t1 = new Thread(() ->{
            //这个线程负责进行等待
            System.out.println("t1 : wait之前");
            try {
                synchronized (object){
                    object.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1 : wait之后");
        });

        Thread t2 = new Thread(() ->{
            //这个线程负责进行通知
            System.out.println("t2 : notify之前");
            //notify必须要获取到锁，才能进行通知
            synchronized (object){
                object.notify();
            }
            System.out.println("t2 : notify之后");

        });
        t1.start();
        Thread.sleep(500);
        t2.start();
    }
}
